package global

import "go.uber.org/zap/zapcore"

// Configuration 系统配置
type Configuration struct {
	System    SystemConfig    `mapstructure:"system" json:"system"`
	Mysql     MysqlConfig     `mapstructure:"mysql" json:"mysql"`
	Logs      LogsConfig      `mapstructure:"logs" json:"logs"`
	Jwt       JwtConfig       `mapstructure:"jwt" json:"jwt"`
	RateLimit RateLimitConfig `mapstructure:"rate-limit" json:"rateLimit"`
	Redis     RedisConfig     `mapstructure:"redis" json:"redis"`
}

type SystemConfig struct {
	Port              int  `mapstructure:"port" json:"port"`
	EnableTransaction bool `mapstructure:"enable-transaction" json:"enableTransaction"`
	EnableRedis       bool `mapstructure:"enable-redis" json:"enableRedis"`
}

type MysqlConfig struct {
	Username    string `mapstructure:"username" json:"username"`
	Password    string `mapstructure:"password" json:"password"`
	Database    string `mapstructure:"database" json:"database"`
	Host        string `mapstructure:"host" json:"host"`
	Port        int    `mapstructure:"port" json:"port"`
	Query       string `mapstructure:"query" json:"query"`
	LogMode     bool   `mapstructure:"log-mode" json:"logMode"`
	TablePrefix string `mapstructure:"table-prefix" json:"tablePrefix"`
}

type LogsConfig struct {
	Level      zapcore.Level `mapstructure:"level" json:"level"`
	Path       string        `mapstructure:"path" json:"path"`
	MaxSize    int           `mapstructure:"max-size" json:"maxSize"`
	MaxBackups int           `mapstructure:"max-backups" json:"maxBackups"`
	MaxAge     int           `mapstructure:"max-age" json:"maxAge"`
	Compress   bool          `mapstructure:"compress" json:"compress"`
}

type JwtConfig struct {
	Realm         string `mapstructure:"realm" json:"realm"`
	Key           string `mapstructure:"key" json:"key"`
	Timeout       int    `mapstructure:"timeout" json:"timeout"`
	MaxRefresh    int    `mapstructure:"max-refresh" json:"maxRefresh"`
	TokenLookup   string `mapstructure:"token-lookup" json:"tokenLookup"`
	TokenHeadName string `mapstructure:"token-head-name" json:"tokenHeadName"`
}

type RateLimitConfig struct {
	Max int64 `mapstructure:"max" json:"max"`
}

type RedisConfig struct {
	Host      string `mapstructure:"host" json:"host"`
	Port      int    `mapstructure:"port" json:"port"`
	Password  string `mapstructure:"password" json:"password"`
	Database  int    `mapstructure:"database" json:"database"`
	BinlogPos string `mapstructure:"binlog-pos" json:"binlogPos"`
}
